package com.zhz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhz.feign.UserServiceFeign;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhz.domain.WorkIssue;
import com.zhz.mapper.WorkIssueMapper;
import com.zhz.service.WorkIssueService;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

/**
 * @author ：zhz
 * @date ：Created in 2020/12/20
 * @version: V1.0
 * @slogan: 天下风云出我辈，一入代码岁月催
 * @description:
 **/
@Service
public class WorkIssueServiceImpl extends ServiceImpl<WorkIssueMapper, WorkIssue> implements WorkIssueService {

    private UserServiceFeign userServiceFeign;
    /**
     * 条件分页查询工单列表
     *
     * @param page      分页参数
     * @param status    工单的状态
     * @param startTime 查询的工单创建起始时间
     * @param endTime   查询的工单创建截至时间
     * @return
     */
    @Override
    public Page<WorkIssue> findByPage(Page<WorkIssue> page, Integer status, String startTime, String endTime) {
        Page<WorkIssue> issuePage = page(page, new LambdaQueryWrapper<WorkIssue>()
                .eq(status != null, WorkIssue::getStatus, startTime)
                .between(
                        !StringUtils.isEmpty(startTime) && !StringUtils.isEmpty(endTime),
                        WorkIssue::getCreated,
                        startTime,
                        endTime + " 23:59:59")
        );
        List<WorkIssue> records = issuePage.getRecords();
        if (CollectionUtils.isEmpty(records)){
            return issuePage;
        }
        //远程调用member-service
        //1、收集ID
        records.stream().map(WorkIssue::getUserId).collect(Collectors.toList());
        //2、远程调用
      /*  userServiceFeign.getBasicUsers();
        records.forEach(workIssue -> {//循环每一个workIssue，给它里面设置用户的信息
            workIssue.setUsername();
            workIssue.setRealName();

        });*/
        return null;
    }

    /**
     * 前台系统查询客户工单
     *
     * @param page
     * @param userId 会员的Id
     * @return
     */
    @Override
    public Page<WorkIssue> getIssueList(Page<WorkIssue> page, Long userId) {
        return null;
    }
}
